import { REPOSTS_KEY_VALUE_MAP } from '@/common/data-drive-ui'
import { mapActions } from 'vuex'

export const dataUtils = {
  computed: {
    dataKeys: {
      get(){
        let keys = []
        if(this.componentData){
          if(_.isArray(this.componentData.dataKeys)){
            keys = this.componentData.dataKeys
          }else{
            _.forEach(this.componentData.dataKeys, (text) => {
              keys.push(text)
            })
          }
        }
        return keys
      },
      set(keys_){
        let dataKeys = {}
        _.forEach(keys_, (key) => {
          let dataKey =  REPOSTS_KEY_VALUE_MAP[key]
          dataKeys[dataKey] = key
        })
        this.$store.commit('components/updateCurrentComponentDataDataKeys', {dataKeys})
      }
    },
   
  },
  methods: {
    ...mapActions({
    }),
  },
}
